# python
from .. import db

from flask_restful import Resource, fields, marshal_with

food_fields = {
    'id': fields.Integer,
    'food_name': fields.String,  # 食物名称
    'food_category': fields.Integer,  # 食物分类
    'food_image': fields.String,  # 食物图片
    'food_calorie': fields.Float,  # 食物卡路里
    'food_protein': fields.Float,  # 食物蛋白质
    'food_fat': fields.Float,  # 食物脂肪
    'food_carbohydrate': fields.Float,  # 食物碳水化合物
    'food_fiber': fields.Float,  # 食物纤维
    'food_vitamin_a': fields.Float,  # 食物维生素A
    'food_vitamin_b': fields.Float,  # 食物维生素B1
    'food_vitamin_c': fields.Float,  # 食物维生素C
    'food_vitamin_e': fields.Float,  # 食物维生素E
    'food_carotene': fields.Float,  # 食物胡萝卜素
    'food_cholesterol': fields.Float,  # 食物胆固醇
    'food_mg': fields.Float,  # 食物镁
    'food_ca': fields.Float,  # 食物钙
    'food_fe': fields.Float,  # 食物铁
    'food_zn': fields.Float,  # 食物锌
    'food_se': fields.Float,  # 食物硒
    'food_cu': fields.Float,  # 食物铜
    'food_mn': fields.Float,  # 食物锰
    'food_k': fields.Float,  # 食物钾
    'food_p': fields.Float,  # 食物磷
    'food_na': fields.Float,  # 食物钠
    'food_description': fields.String,  # 食物描述
    'create_time': fields.DateTime,  # 创建时间
}


class Food(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    food_name = db.Column(db.String(80), nullable=False)
    food_category = db.Column(db.Integer, nullable=False)
    food_image = db.Column(db.Text)
    food_calorie = db.Column(db.Float)
    food_protein = db.Column(db.Float)
    food_fat = db.Column(db.Float)
    food_carbohydrate = db.Column(db.Float)
    food_fiber = db.Column(db.Float)
    food_vitamin_a = db.Column(db.Float)
    food_vitamin_b = db.Column(db.Float)
    food_vitamin_c = db.Column(db.Float)
    food_vitamin_e = db.Column(db.Float)
    food_carotene = db.Column(db.Float)
    food_cholesterol = db.Column(db.Float)
    food_mg = db.Column(db.Float)
    food_ca = db.Column(db.Float)
    food_fe = db.Column(db.Float)
    food_zn = db.Column(db.Float)
    food_se = db.Column(db.Float)
    food_cu = db.Column(db.Float)
    food_mn = db.Column(db.Float)
    food_k = db.Column(db.Float)
    food_p = db.Column(db.Float)
    food_na = db.Column(db.Float)
    food_description = db.Column(db.String(120))
    create_time = db.Column(db.DateTime, server_default=db.func.now())
    def to_dict(self):
        return {
            'id': self.id,
            'food_name': self.food_name,
            'food_category': self.food_category,
            'food_image': self.food_image,
            'food_calorie': self.food_calorie,
            'food_protein': self.food_protein,
            'food_fat': self.food_fat,
            'food_carbohydrate': self.food_carbohydrate,
            'food_fiber': self.food_fiber,
            'food_vitamin_a': self.food_vitamin_a,
            'food_vitamin_b': self.food_vitamin_b,
            'food_vitamin_c': self.food_vitamin_c,
            'food_vitamin_e': self.food_vitamin_e,
            'food_carotene': self.food_carotene,
            'food_cholesterol': self.food_cholesterol,
            'food_mg': self.food_mg,
            'food_ca': self.food_ca,
            'food_fe': self.food_fe,
            'food_zn': self.food_zn,
            'food_se': self.food_se,
            'food_cu': self.food_cu,
            'food_mn': self.food_mn,
            'food_k': self.food_k,
            'food_p': self.food_p,
            'food_na': self.food_na,
            'food_description': self.food_description,
            'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S')

        }

    def __repr__(self):
        return f'<Food {self.username}>'
